<?php

class Application_Model_dataDAO_DBConnect {
	public static function conn() {
			$connParams = array ("host" => "127.0.0.1", 
								"port" => "3306", 
								"username" => "root", 
								"password" => "", 
								"dbname" => "projectMobile" );
			$db = new Zend_Db_Adapter_Pdo_Mysql ( $connParams );
			return $db;
		}
	public static function close($db){
		$db->closeConnection();
	}
	
	public static function updateQuery($table,$dataArray,$conditions){
		$result=false;
		try {
			$db=Application_Model_dataDAO_DBConnect::conn();
			$value=$db->update($table,$dataArray,$conditions);
			if($value==1) $result=true;
			$db->closeConnection();
		} catch (Zend_Db_Exception  $e) {
			echo $e->getMessage();
		}
		return $result;
	}
	
	public static  function insertQuery($table,$data){
		$result=0;
		try {
			$db=Application_Model_dataDAO_DBConnect::conn();
			$db->insert($table,$data);
			$result=$db->lastInsertId();
			Application_Model_dataDAO_DBConnect::close($db);
			
		} catch (Zend_Db_Exception  $e) {
			echo $e->getMessage();
		}
		return $result;
	}
	
	public static  function selectQuery($statement){
		$result=array();
		try {
			$db=Application_Model_dataDAO_DBConnect::conn();
			$result=$db->fetchAll($statement);
			$db->closeConnection();
		} catch (Zend_Db_Exception  $e) {
			echo $e->getMessage();
		}
		return $result;
	}
	public static function deleteQuery($table,$conditions){
		$result=0;
		try {
			$db=Application_Model_dataDAO_DBConnect::conn();
			$result2=$db->delete($table,$conditions);
			if($result2>0){
				$result=$result2;
			}
			$db->closeConnection();
		} catch (Zend_Db_Exception  $e) {
			echo $e->getMessage();
		}
		return $result;//tra ve so record da bi xoa
	}
}

?>